<template>
  
      <mt-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" ref="loadmore" :auto-fill="false">
          <div class="goodslist-banner">
            <div class="goodsinfo" v-for="item in goodsList" :key="item.id" @click="tapgoodsinfo(item.id)">
                <img :src="item.img_url" alt="">
                <h1 class="titls">{{item.title}}</h1>
                <div class="message">
                    <p class="price">
                        <span class="newPrice">现价:{{item.sell_price}}</span>
                        <span class="oldPrice">原价:{{item.market_price}}</span>
                    </p>
                    <p class="num">
                        <span class="progress">热卖中</span>
                        <span class="sale">库存:{{item.stock_quantity}}</span>
                    </p>
                </div>
            </div>
       </div>
      </mt-loadmore>
 
</template>
<script>
import { Loadmore } from "mint-ui";
export default {
  data() {
    return {
      pageindex: 1,
      goodsList: [],
      allLoaded: false
    };
  },
  created() {
    this.getMsg();
  },
  methods: {
    getMsg() {
      this.$axios
        .get("api/getgoods?pageindex=" + this.pageindex)
        .then(results => {
          if (this.pageindex == 1) {
            this.$refs.loadmore.onTopLoaded();
            this.goodsList = results.data.message;
          }
        });
    },
    getMore() {
      this.$axios
        .get("api/getgoods?pageindex=" + this.pageindex)
        .then(results => {
          this.goodsList = this.goodsList.concat(results.data.message);
          if (results.data.message.length < 10) {
            this.allLoaded = true;
            this.$refs.loadmore.onBottomLoaded();
          }
        });
    },
    loadTop() {
      console.log(this.pageindex);
      setTimeout(() => {
        this.pageindex = 1;
        this.getMsg();
        this.allLoaded = false;
      },1000);
    },
    loadBottom() {
      console.log(this.pageindex);
      this.pageindex++;
      setTimeout(() => {
        this.getMore();
      }, 1000);
    },
    tapgoodsinfo(id){
        this.$router.push({name:'goodsinfo',params:{id}})
        console.log(id)
    }
  }
};
</script>
<style lang="scss" scoped>
.goodslist-banner {
  padding: 10px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  .goodsinfo {
    width: 48.8%;
    padding: 1%;
    box-shadow: 0 0 5px #000;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    img {
      width: 100%;
    }
    h1 {
      font-size: 14px;
    }
    .message {
      p {
        font-size: 12px;
        margin: 0;
      }
      .price {
        .newPrice {
          font-size: 16px;
          color: red;
          font-weight: bold;
        }
        .oldPrice {
          margin-left: 10px;
          text-decoration: line-through;
        }
      }
      .num {
        .progress {
          color: #000;
          margin-right: 10px;
        }
        .sale {
          color: #333;
        }
      }
    }
  }
}
</style>
